import request from "@/utils/request"

const API = {
  // 获取全部职位
  ALLROLE_URL: 'admin/acl/role/',
  // 新增岗位的地址
  ADDROLE_URL: 'admin/acl/role/save',
  // 更新已有的职位
  UPDATEROLE_URL: 'admin/acl/role/update',
  // 获取全部菜单与按钮数据
  ALLPERMISSION: 'admin/acl/permission/toAssign/',
  // 给相应的职位分配权限
  SETPERMISSION_URL: 'admin/acl/permission/doAssign/?',
  // 删除已有的职位
  REMOVEROLE_URL: 'admin/acl/role/remove/'
}

// 获取全部角色
export const getAllRoleAPI = (page, limit, rolename) => request.get(API.ALLROLE_URL + `${page}/${limit}/?roleName=${rolename}`)

// 添加职位与更新已有职位
export const addOrUpdateRoleAPI = (data) => {
  if(data.id) {
    return request.put(API.UPDATEROLE_URL, data)
  } else {
    return request.post(API.ADDROLE_URL, data)
  }
}

// 获取全部菜单与按钮的权限数据
export const getAllMenuListAPI = (roleId) => request.get(API.ALLPERMISSION + roleId)

// 给相应职位下发权限
export const setPermissionAPI = (roleId, permissionId) => request.post(API.SETPERMISSION_URL + `roleId=${roleId}&&permissionId=${permissionId}`)

// 删除职位
export const removeRoleAPI = (roleId) => request.delete(API.REMOVEROLE_URL + roleId)